import { BasicColumn, FormSchema } from '/@/components/Table';
import {
  userRemarkFormItem,
  userStatusFormItem,
  userStatusFormItemSelect,
} from '@/settings/ShareFormItem';
import { apiGetDeptsDropdown } from '@/api/http/system/senior/depts/depts.api';
import { defaultRule, rules } from '@/utils/common/validator';
import { userRemarksColumn, userStatusColumn } from '@/settings/ShareTableColumns';

export const useDeptsUpdateSchemaForm = (): FormSchema[] => {
  return [
    { field: 'deptId', label: '部门ID', component: 'Input', show: false },
    {
      field: 'parentId',
      label: '父部门ID',
      component: 'ApiSelect',
      componentProps: { api: apiGetDeptsDropdown, placeholder: '为空时表示顶级', valueField: 'id' },
    },
    {
      field: 'deptName',
      label: '部门名称',
      component: 'Input',

      rules: defaultRule(),
    },
    {
      field: 'orderNum',
      label: '显示顺序',
      component: 'InputNumber',
      defaultValue: 0,
      componentProps: {
        min: 0,
      },
    },
    { field: 'leaderId', label: '负责人', component: 'Input' },
    {
      field: 'phone',
      label: '联系电话',
      component: 'Input',
      rules: [rules.validateNotEmpty('mobile', '联系电话输入有误')],
    },
    {
      field: 'email',
      label: '邮箱',
      component: 'Input',
      rules: [rules.validateNotEmpty('email', '联系电话输入有误')],
    },
    userStatusFormItem(),
    userRemarkFormItem(),
  ];
};

export const useDeptsQueryColumns = (): BasicColumn[] => {
  return [
    { title: '部门名称', dataIndex: 'deptName' },
    { title: '显示顺序', dataIndex: 'orderNum' },
    { title: '负责人', dataIndex: 'leaderName' },
    { title: '联系电话', dataIndex: 'phone' },
    { title: '邮箱', dataIndex: 'email' },
    userStatusColumn(),
    userRemarksColumn(),
    { title: '创建时间', dataIndex: 'createTime' },
  ];
};

export const useDeptsQuerySearchForm = (): FormSchema[] => {
  return [{ field: 'deptName', label: '部门名称', component: 'Input' }, userStatusFormItemSelect()];
};
